Skip to content

Comments

Add type annotations to cqlengine models and query modules#721

Draft
dkropachev wants to merge 1 commit intomasterfrom
fix-engine-typing
Draft

Add type annotations to cqlengine models and query modules#721
dkropachev wants to merge 1 commit intomasterfrom
fix-engine-typing

Conversation

@dkropachev
Copy link
Collaborator

Summary

Based on https://github.com/VincentRPS/python-driver/tree/fix-engine-typing with the following fixes applied:

  • Add from __future__ import annotations to both models.py and query.py (the original PR only added it to query.py but used float | None / list[M] syntax in models.py)
  • Fix AbstractQuerySet.__ne__ infinite recursion bug: return not (self != q)return not (self == q)
  • Fix all() and filter() return types to ModelQuerySet instead of list[M] (they return querysets, not lists)
  • Drop incorrect BaseModel.__getitem__(slice | int) that would override the existing column-access __getitem__(str) and break it
  • Drop wrong objects: query.ModelQuerySet type annotation (attribute is a QuerySetDescriptor, not a ModelQuerySet)
  • Drop unused T = TypeVar('T', bound=ModelQuerySet) that had a forward reference issue

Test plan

  • uv run pytest tests/unit/cqlengine/ passes (13/13)
  • Runtime import verification passes
  • Full unit test suite

Based on VincentRPS/python-driver#fix-engine-typing with fixes:
- Add `from __future__ import annotations` to both files
- Fix `__ne__` infinite recursion bug (`not (self != q)` -> `not (self == q)`)
- Fix `all()` and `filter()` return types to return `ModelQuerySet` not `list`
- Drop incorrect `__getitem__` override on BaseModel (would break column access)
- Drop wrong `objects: query.ModelQuerySet` annotation (it's a descriptor)
- Drop unused `T = TypeVar` with forward reference issue

import logging
import re
from typing import TYPE_CHECKING, TypeVar
from datetime import datetime, timedelta
from functools import partial
import time
from typing import TYPE_CHECKING, TypeVar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant